/***************************************************************************
 *   Copyright (C) 2008 by Ivan Blagoev Topolsky   *
 *   ivan.topolsky@genebio.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef DBSEQUENCEDIGESTORFACTORY_H
#define DBSEQUENCEDIGESTORFACTORY_H

#include "dbsequencefactory.h"
#include "enzyme.h"
#include "peptidefromsequence.h"

#ifndef PEPTIDE_DIGEST_LENGTH_MIN
#define PEPTIDE_DIGEST_LENGTH_MIN	6
#endif

#ifndef PEPTIDE_DIGEST_LENGTH_MAX
#define PEPTIDE_DIGEST_LENGTH_MAX	30
#endif

/**
class that parses a given DBSequenceFactory and digests the resulting peptide using a given enzyme

	@author Ivan Topolsky,,, <ivan.topolsky@genebio.com>
*/


namespace bol{
typedef boost::shared_ptr<PeptideFromSequence> PeptideFromSequencePtr;

class DBSequenceDigestorFactory{
    DBSequenceFactory *m_factory;
    Enzyme *m_enzyme;

    int m_nummiscleavage;
    int m_minlength;
    int m_maxlength;

    vector<PeptideFromSequencePtr> peptcollection;
    int collectionsize;
protected:
    int fillCollection();
public:
    DBSequenceDigestorFactory(DBSequenceFactory *dbseqfact = NULL, Enzyme *enz = NULL, int miscleave = 0) {
      setDBSequenceFactory(dbseqfact);
      setEnzyme(enz);
      setNumMisCleavage(miscleave);
      setLengthLimits(PEPTIDE_DIGEST_LENGTH_MIN,PEPTIDE_DIGEST_LENGTH_MAX);
      peptcollection.clear();
      collectionsize = 0;
    }

    ~DBSequenceDigestorFactory() {}


  /**
   * set from which database we get sequence
   * @param dbseqfac
   */
    void setDBSequenceFactory(DBSequenceFactory *dbseqfact) {
      m_factory = dbseqfact;
    }


  /**
   * set which Enzyme we should use to cleave the database's sequence
   * @param enz
   */
    void setEnzyme(Enzyme *enz) {
      m_enzyme = enz;
    }

  /**
   * set how many Enzyme mis-cleavage(s) we should take into acount
   * @param num
   */
    void setNumMisCleavage(int num) {
      m_nummiscleavage = num;
    }

  /**
   * set a range of possible digested peptide lengths that we consider
   * @param min
   * @param max
   */
    void setLengthLimits(int min, int max) {
      setMinLength(min);
      setMaxLength(max);
    }

  /**
   * set the minimum length that we consider for a digested peptide 
   * @param min
   */
    void setMinLength(int min) {
      m_minlength = min;
    }

  /**
   * set the minimum length that we consider for a digested peptide 
   * @param max
   */
    void setMaxLength(int max) {
      m_maxlength = max;
    }

    /**
     * get the next available digested peptide
     * @param ptr put it there
     * @return true if there was an available peptide, false if we can't get any more peptides
     */
    bool nextPeptide(PeptideFromSequencePtr &ptr);
};
}

#endif
